package com.ldgame.game;

import org.lwjgl.input.Keyboard;
import org.lwjgl.util.vector.Vector2f;
import org.newdawn.slick.Color;

import com.ldgame.gfx.gfxelements.Label;
import com.ldgame.gfx.gfxelements.Sprite;
import com.ldgame.input.Input;
import com.ldgame.utils.Button;
import com.ldgame.utils.HowToAction;
import com.ldgame.utils.NewGameAction;
import com.ldgame.utils.ResetAction;
import com.ldgame.utils.ToggleAudioAction;

public class MenuState implements GameState {
	private Game game;
	private Sprite bg = new Sprite(new Vector2f(400.0f, 300.0f),
								   800.0f,
								   800.0f,
								   new Vector2f(96.0f, 0.0f),
								   new Vector2f(168.0f, 168.0f),
								   new Color(1.0f, 1.0f, 1.0f, 1.0f));
	private Label title = new Label(48.0f, new Color(0.5f, 0.8f, 0.3f, 1.0f));
	private Label intro = new Label(16.0f, new Color(0.8f, 0.5f, 0.0f, 1.0f));
	private Label newGameLabel = new Label(32.0f, new Color(0.6f, 0.5f, 0.3f, 1.0f));
	private Label howToLabel = new Label(32.0f, new Color(0.6f, 0.5f, 0.3f, 1.0f));
	private Label audio = new Label(8.0f, new Color(1.0f, 1.0f, 1.0f, 1.0f));
	private Label reset = new Label(8.0f, new Color(0.6f, 0.5f, 0.3f, 1.0f));
	private Button newGameButton;
	private Button howToButton;
	private Button resetButton;
	private Button toggleAudioButton;
	
	public MenuState(Game game) {
		this.game = game;
		
		newGameButton = new Button(newGameLabel, new NewGameAction(game));
		newGameButton.setColors(new Color(0.6f, 0.5f, 0.3f, 1.0f), new Color(1.0f, 0.8f, 0.6f, 1.0f));
		
		howToButton = new Button(howToLabel, new HowToAction(game));
		howToButton.setColors(new Color(0.6f, 0.5f, 0.3f, 1.0f), new Color(1.0f, 0.8f, 0.6f, 1.0f));
		
		toggleAudioButton = new Button(audio, new ToggleAudioAction());
		resetButton = new Button(reset, new ResetAction(game));
	}
	
	@Override
	public void handleInput() {
		if (Input.checkReleasedKey(Keyboard.KEY_ESCAPE)) {
			if (game.getRunningGame() == null) {
				game.setRunningGame(new RunningState(game));
			}
			game.setGameState(game.getRunningGame());
		}
	}

	@Override
	public void calcConfig() {
		newGameButton.listen();
		howToButton.listen();
		toggleAudioButton.listen();
		resetButton.listen();
	}

	@Override
	public void render() {
		bg.render();
		title.render("FREE DONUTIA", new Vector2f(400.0f, 80.0f));
		intro.render("As the last member of the ancient race from", new Vector2f(400.0f, 180.0f));
		intro.render("the planet Floss, born and raised on the", new Vector2f(400.0f, 230.0f));
		intro.render("little planet of Donutia, you must help", new Vector2f(400.0f, 280.0f));
		intro.render("the Donutians save their land from the evil", new Vector2f(400.0f, 330.0f));
		intro.render("plans of the Tiny Aliens!", new Vector2f(400.0f, 380.0f));
		newGameLabel.render("Play!", new Vector2f(400.0f, 500.0f));
		howToLabel.render("How to play", new Vector2f(400.0f, 550.0f));
		audio.render("Toggle Music", new Vector2f(80.0f, 570.0f));
		reset.render("Reset game", new Vector2f(720.0f, 570.0f));
	}
}
